﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
@using LeSoft.Util;
<script>
    var _State = "", Type = "";
    $(function () {
         InitialPage();
        GetGrid();
        Initial();
        GetTree();
    }) 
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 181.5);

            }, 200);
            e.stopPropagation();

        });
        //初始化时间
        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day+1).ToString("yyyy-MM-dd")");
        $("#EndTime").val("@DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
        $("#time_horizon").ComboBox({
            data: [{ "key": 2, "value": "上周" }, { "key": 1, "value": "本周" }, { "key": 4, "value": "上月" }, { "key": 3, "value": "本月" }, { "key": 5, "value": "本年" }],
            id: "key",
            text: "value",
            description: "=选择=",
            click: function (item) {

                var value = item.attr('data-value');
                switch (value) {
                    case "1"://本周
                        $("#StartTime").val("@DateTime.Now.AddDays(1 - DateTime.Now.DayOfWeek.GetHashCode()).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(7 - DateTime.Now.DayOfWeek.GetHashCode()).ToString("yyyy-MM-dd")");
                        break;
                    case "2"://上周
                        $("#StartTime").val("@DateTime.Now.AddDays(1 - DateTime.Now.DayOfWeek.GetHashCode()-7).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(7 - DateTime.Now.DayOfWeek.GetHashCode()-7).ToString("yyyy-MM-dd")");
                        break;
                    case "3"://本月
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day+1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    case "4"://上月
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day + 1).AddMonths(-1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    case "5"://本年
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.DayOfYear + 1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddMonths(12 - DateTime.Now.Month + 1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    default:
                        break;
                }
                $("#SelectedStartTime").html($("#StartTime").val());
                $("#SelectedEndTime").html($("#EndTime").val());
                SearchEvent();
            }
        });
        $("#time_horizon").ComboBoxSetValue(3);

    }

    function Initial() {

        $("#Category").ComboBox({
            data: [{ "key": "1", "value": "初次申请" }, { "key": "2", "value": "再次申请" }, { "key": "3", "value": "续租申请" }, { "key": "4", "value": "再次续租申请" }],
            id: "key",
            text: "value",
            description: "=选择业务状态=",
            height: "200px",
            click: function (item) {
                SearchEvent();
            }
        });
    }
    function GetTree() {
        debugger;
        var item = {
            height: $(window).height() - 55.5,
            url: "../../QualificationManage/Retrial/GetTreeListTojson",
            onnodeclick: function (item) {
                switch (item.id) {
                    case "All":
                        _State = -1;
                        break;
                    case "AllCheck":
                        _State = -2;
                        break;
                    case "Checked":
                        _State = 4;
                        break;
                    case "CityChceking":
                        _State = 5;
                        break;
                    case "CenterChecking":
                        _State = 6;
                        break;
                    case "CenterChecked":
                        _State = 7;
                        break;
                    case "YFS":
                        _State = 7;
                        break;
                    case "CenterUnChecked":
                        _State = 8;
                        break;
                    case "ReturnBack":
                        _State = 9;
                        break;

                    default: break;
                }
                SearchEvent();
            }
        };
        //初始化
        $("#itemTree1").treeview(item);
    }

    function GetGrid() {
        var selectedRowIndex = 0;
        $gridTable = $("#gridTable");
        var queryJson = {
            State: _State,
            StartTime: $("#StartTime").val(),
            EndTime: $("#EndTime").val() + " 23:59:59",
            Name: $("#Name").val(),
            IDCard: $("#IDCard").val(),
            Category: $("#Category").attr("data-value"),
            Phone: $("#Phone").val()
        };
        $gridTable.jqGrid({
            url: "../../QualificationManage/Retrial/GetPageList",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 141,
            autowidth: true,
            multiselect: true,
            colModel: [
                { label: "主键", name: "Id", hidden: true },
                { label: "市局编号", name: "CityBurceauCode", index: "CityBurceauCode", width: 160, align: "center", sortable: false },
                { label: "申请人", name: "MemberId", index: "MemberId", width: 100, align: "center", sortable: false },
                { label: "身份证号码", name: "Address", index: "Address", width: 200, align: "center", sortable: false },
                {
                    label: "性别", name: "FamilyType", index: "FamilyType", width: 80, align: "center", sortable: false,
                    formatter: function (cellvalue) {
                        switch (cellvalue) {
                            case 1:
                                return "男";
                            case 2:
                                return "女";
                            default: return cellvalue;

                        }
                    }
                },
                { label: "手机号", name: "PostalCode", index: "PostalCode", width: 200, align: "center", sortable: false },
                { label: "单据编号", name: "Code", index: "Code", width: 200, align: "center", sortable: false },

                 {
                     label: "状态", name: "State", index: "State", width: 200, align: "center", sortable: false,
                     formatter: function (cellvalue, options, rowObject) {
                         var Msg = "";
                         switch (cellvalue) {
                             case 1: Msg = "<span  class='label' style='background-color:#74B981'>初审中（初次)</span>";
                                 break;
                             case 2: Msg = "<span  style='background-color:#6ABD78' class='label '>初审中（再次）</span>";
                                 break;
                             case 0:
                             case 3: Msg = "<span  style='background-color:#B05B5C' class='label '>初审未通过</span>";
                                 break;
                             case 4: Msg = "<span  style='background-color:#CCE099' class='label '>递交资料中</span>";
                                 break;
                             case 5: Msg = "<span  style='background-color:#C1D169' class='label '>市局审批中（材料通过）</span>";
                                 break;
                             case 6: Msg = "<span  style='background-color:#15AD66' class='label '>复审（市局审批通过）</span>";
                                 break;
                             case 7: Msg = "<span  style='background-color:#5CB85C' class='label '>复审通过</span>";
                                 break;
                             case 8: Msg = "<span  class='label'  style='background-color:#f00' >复审未通过</span>";
                                 break;
                             case 9: Msg = "<span  style='background-color:#ccc' class='label '>客户撤回</span>";
                                 break;
                             case 10: Msg = "<span  style='background-color:#B05B5C' class='label '>材料未通过</span>";
                                 break;
                             default: Msg = "---";
                                 break;
                         }
                         return Msg;
                     }
                 },
                {
                    label: "业务类型", name: "Category", index: "Category", width: 100, align: "center", sortable: false,
                    formatter: function (cellvalue) {
                        var Msg = "";
                        switch (cellvalue) {
                            case 1: Msg = "初次申请";
                                break;
                            case 2: Msg = "再次申请";
                                break;
                            case 3: Msg = "续租申请";
                                break;
                            case 4: Msg = "再次续租申请";
                                break;
                            default: Msg = "---";
                                break;
                        }
                        return Msg;
                    }
                },
                 { label: "单据时间", name: "Date", index: "Date", width: 200, align: "center", sortable: false },
                 {
                     label: "审核时长(工作日)", name: "ReCheckDay", index: "ReCheckDay", width: 140, align: "center", cellattr: addCellAttr, sortable: false,
                     formatter: function (cellvalue, options, rowObject) {
                         if (parseInt(cellvalue) > 0) return cellvalue + "天";
                         return "";
                      }
                  },
            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortname: 'CityBurceauCode',
            sortorder: 'asc',
            rownumbers: true,
            gridview: true,
            onSelectRow: function (status) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
                var ids = $("#gridTable").getDataIDs();
                for (var i = 0; i < ids.length; i++) {
                    var rowData = $("#gridTable").getRowData(ids[i]);
                    if (rowData.UseMark == -1) {
                        $('#' + ids[i]).find("td").addClass("differentFlag");
                    }
                }

            },
        });
        //查询事件
        $("#btn_Search").click(function () {
            SearchEvent();
            $('#btn_Reset').trigger("click");
            $(".ui-filter-text").trigger("click");
        });
        $("#btn_Reset").click(function () {
            $("#Name").val("");
            $("#IDCard").val("");
            $("#Phone").val("");
        })

    }
    function addCellAttr(rowId, val, rowObject, cm, rdata) {
        if (parseInt(rowObject.ReCheckDay) > 20 && (rowObject.State == 4 || rowObject.State == 5 || rowObject.State == 6)) {
             return "style='background-color:red'";
        }
    }
    function SearchEvent() {
        var queryJson = {
            State: _State,
            StartTime: $("#StartTime").val(),
            EndTime: $("#EndTime").val() + " 23:59:59",
            Name: $("#Name").val(),
            IDCard: $("#IDCard").val(),
            Category: $("#Category").attr("data-value"),
            Phone: $("#Phone").val()
        };
        $("#gridTable").jqGrid('setGridParam', {
            url: "../../QualificationManage/Retrial/GetPageList",
            postData: { queryJson: JSON.stringify(queryJson) },
        }).trigger('reloadGrid');
        $("#Name").val("");
        $("#IDCard").val("");
        $("#Phone").val("")
    }
    function btn_export() {
        var queryJson = {
            State: _State,
            StartTime: $("#StartTime").val(),
            EndTime: $("#EndTime").val() + " 23:59:59",
            Name: $("#Name").val(),
            IDCard: $("#IDCard").val(),
            Category: $("#Category").attr("data-value"),
            Phone: $("#Phone").val()
        };
        location.href = "../../QualificationManage/Retrial/GetExportList?queryJson=" + JSON.stringify(queryJson);
    }
    function btn_detail() {
        var keyValue = $("#gridTable").jqGridRowValue("Code");
        if (checkedRow(keyValue)) {
            top.tablist.newTab({
                id: "RetrialForm-" + keyValue,
                title: '单据详情【复审】',
                closed: true,
                icon: "fa fa-eye",
                url: top.contentPath + '/QualificationManage/Retrial/Form?keyValue=' + keyValue
            });
        }

    }
    //批量审核
    function btn_allTrial() {
        var QuaCheckSecurity = "@LeSoft.Application.Bussiness.WorkRoleSettingBLL.GetIsAudit(Convert.ToInt32(LeSoft.Application.Code.WorkRoleEnum.QuaCheckSecurity))";
        var QuaCheckCenter = "@LeSoft.Application.Bussiness.WorkRoleSettingBLL.GetIsAudit(Convert.ToInt32(LeSoft.Application.Code.WorkRoleEnum.QuaCheckCenter))";
        if (QuaCheckCenter == "False" && QuaCheckSecurity=="False") {
            dialogMsg('您不是该业务的处理人！', 0);
            return false;
        }
        var keyValue = $("#gridTable").jqGridRowValue("Code"); 
        if (keyValue == "") {
            dialogMsg('至少选择一条数据进行操作！', 0);
            return false;
        }
        else {
            dialogOpen({
                id: "AllForm",
                title: '批量审核',
                url: '/QualificationManage/Retrial/AllForm?keyValue=' + keyValue,
                width: "500px",
                height: "400px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            })
        }
    }
</script>
<style>
    .differentFlag {
        background-color: #f00;
    }
</style>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel">
            <div class="panel-Title" style="padding:0px; text-align:center;">单据状态</div>
            <div id="itemTree1">
            </div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="titlePanel">
                <div class="title-search ">
                    <table>
                        <tr>
                            <td>查询条件</td>
                            <td style="padding-left: 10px;">
                                <div class="ui-filter" style="width: 200px;">
                                    <div class="ui-filter-text">
                                        <strong id="SelectedStartTime">@DateTime.Now.AddDays(-DateTime.Now.Day + 1).ToString("yyyy-MM-dd")</strong> 至 <strong id="SelectedEndTime">@DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")</strong>
                                    </div>
                                    <div class="ui-filter-list" style="width: 350px;">
                                        <table class="form" id="filter-form">
                                            <tr>
                                                <th class="formTitle">单据时间：</th>
                                                <td class="formValue">
                                                    <div style="float: left; width: 45%;">
                                                        <input id="StartTime" readonly type="text" value="2017-07-01" class="form-control input-wdatepicker" onfocus="WdatePicker()">
                                                    </div>
                                                    <div style="float: left; width: 10%; text-align: center;">至</div>
                                                    <div style="float: left; width: 45%;">
                                                        <input id="EndTime" readonly type="text" value="2017-07-31" class="form-control input-wdatepicker" onfocus="WdatePicker()">
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">姓名：</td>
                                                <td class="formValue">
                                                    <input id="Name" maxlength="20" type="text" class="form-control">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">身份证号：</td>
                                                <td class="formValue">
                                                    <input id="IDCard" maxlength="20" type="text" class="form-control">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">手机号：</td>
                                                <td class="formValue">

                                                    <input id="Phone" maxlength="20" type="text" class="form-control">
                                                </td>
                                            </tr>

                                        </table>
                                        <div class="ui-filter-list-bottom">
                                            <a id="btn_Reset" class="btn btn-default">&nbsp;重&nbsp;&nbsp;置</a>
                                            <a id="btn_Search" class="btn btn-primary">&nbsp;查&nbsp;&nbsp;询</a>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td style="padding-left: 10px;">
                                <div id="time_horizon" type="selectTree" class="ui-select" style="width: 60px;"></div>
                            </td>

                            <td style="padding-left: 10px;">
                                <div id="Category" type="selectTree" class="ui-select" style="width:150px;"></div>
                            </td>

                        </tr>

                    </table>

                </div>

                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default " onclick="reload(); "><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-detail" class="btn btn-default " onclick="btn_detail()"><i class="fa fa-eye"></i>&nbsp;查看</a>
                        <a id="lr-add" class="btn btn-default " onclick="btn_allTrial()"><i class="fa fa-wrench"></i>&nbsp;批量审核</a>
                        <a id="lr-export" class="btn btn-default" onclick="btn_export()"><i class="fa fa-sign-out"></i>&nbsp;导出</a>
                    </div>
                    <script>$('.toolbar').authorizeButton()</script>
                </div>
            </div>


            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>

        </div>
    </div>
</div>


